"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
const tiny_entity2_1 = require("tiny-entity2");
const EntityObjectType = tiny_entity2_1.EntityObjectFactory.GetEntityObjectType(process.env.dataBaseType || 'mysql');
const unit_1 = require("./unit");
const combo_1 = require("./combo");
const storeStock_1 = require("./storeStock");
let Product = class Product extends EntityObjectType {
    get ProductType() {
        return ProductType.Prase(this.type);
    }
};
__decorate([
    tiny_entity2_1.Define.PrimaryKey(),
    __metadata("design:type", String)
], Product.prototype, "id", void 0);
__decorate([
    tiny_entity2_1.Define.Column({
        DataType: tiny_entity2_1.Define.DataType.VARCHAR,
        NotAllowNULL: true
    }),
    __metadata("design:type", String)
], Product.prototype, "name", void 0);
__decorate([
    tiny_entity2_1.Define.Column({
        DataType: tiny_entity2_1.Define.DataType.BIGINT
    }),
    __metadata("design:type", Number)
], Product.prototype, "createTime", void 0);
__decorate([
    tiny_entity2_1.Define.Column({
        DataType: tiny_entity2_1.Define.DataType.BIGINT
    }),
    __metadata("design:type", Number)
], Product.prototype, "version", void 0);
__decorate([
    tiny_entity2_1.Define.Column({
        DataType: tiny_entity2_1.Define.DataType.VARCHAR,
        NotAllowNULL: true
    }),
    __metadata("design:type", String)
], Product.prototype, "code", void 0);
__decorate([
    tiny_entity2_1.Define.Column({
        DataType: tiny_entity2_1.Define.DataType.VARCHAR
    }),
    __metadata("design:type", String)
], Product.prototype, "pinyin", void 0);
__decorate([
    tiny_entity2_1.Define.Column(),
    __metadata("design:type", String)
], Product.prototype, "fullPinyin", void 0);
__decorate([
    tiny_entity2_1.Define.Column(),
    __metadata("design:type", String)
], Product.prototype, "numPy", void 0);
__decorate([
    tiny_entity2_1.Define.Column({
        DataType: tiny_entity2_1.Define.DataType.Decimal,
        DataLength: 11,
        DecimalPoint: 3,
        NotAllowNULL: true
    }),
    __metadata("design:type", Number)
], Product.prototype, "price", void 0);
__decorate([
    tiny_entity2_1.Define.Column({
        DataType: tiny_entity2_1.Define.DataType.VARCHAR,
        DefaultValue: 'normal'
    }),
    __metadata("design:type", String)
], Product.prototype, "status", void 0);
__decorate([
    tiny_entity2_1.Define.Column({
        DataType: tiny_entity2_1.Define.DataType.BOOL
    }),
    __metadata("design:type", Boolean)
], Product.prototype, "autoAdd", void 0);
__decorate([
    tiny_entity2_1.Define.Column({
        DataType: tiny_entity2_1.Define.DataType.VARCHAR
    }),
    __metadata("design:type", String)
], Product.prototype, "description", void 0);
__decorate([
    tiny_entity2_1.Define.Column({
        DataType: tiny_entity2_1.Define.DataType.VARCHAR,
        IsIndex: true,
        NotAllowNULL: true
    }),
    __metadata("design:type", String)
], Product.prototype, "storeId", void 0);
__decorate([
    tiny_entity2_1.Define.Column({
        DataType: tiny_entity2_1.Define.DataType.VARCHAR
    }),
    __metadata("design:type", String)
], Product.prototype, "unitId", void 0);
__decorate([
    tiny_entity2_1.Define.Mapping({
        Mapping: 'Unit',
        MappingKey: { FKey: "id", MKey: "unitId" },
        MappingType: tiny_entity2_1.Define.MappingType.One
    }),
    __metadata("design:type", unit_1.Unit)
], Product.prototype, "unit", void 0);
__decorate([
    tiny_entity2_1.Define.Column({
        DataType: tiny_entity2_1.Define.DataType.INT,
        DefaultValue: 0
    }),
    __metadata("design:type", Number)
], Product.prototype, "indexNo", void 0);
__decorate([
    tiny_entity2_1.Define.Column({
        DataType: tiny_entity2_1.Define.DataType.VARCHAR,
        DefaultValue: 'normal'
    }),
    __metadata("design:type", String)
], Product.prototype, "type", void 0);
__decorate([
    tiny_entity2_1.Define.Mapping({
        Mapping: 'Combo',
        MappingKey: 'productId',
        MappingType: tiny_entity2_1.Define.MappingType.One
    }),
    __metadata("design:type", combo_1.Combo)
], Product.prototype, "combo", void 0);
__decorate([
    tiny_entity2_1.Define.Mapping({
        Mapping: 'Modifier',
        MappingKey: 'productId'
    }),
    __metadata("design:type", Array)
], Product.prototype, "modifiers", void 0);
__decorate([
    tiny_entity2_1.Define.Mapping({
        Mapping: 'ProductCategory',
        MappingKey: 'productId'
    }),
    __metadata("design:type", Array)
], Product.prototype, "productCategory", void 0);
__decorate([
    tiny_entity2_1.Define.Mapping({
        Mapping: 'StoreStock',
        MappingKey: { FKey: 'productId', MKey: 'id' },
        MappingType: tiny_entity2_1.Define.MappingType.One
    }),
    __metadata("design:type", storeStock_1.StoreStock)
], Product.prototype, "storeStock", void 0);
__decorate([
    tiny_entity2_1.Define.Mapping({
        Mapping: 'ImageStore',
        MappingKey: { FKey: 'objectId', MKey: 'id' }
    }),
    __metadata("design:type", Array)
], Product.prototype, "images", void 0);
Product = __decorate([
    tiny_entity2_1.Define.Table({ TableName: 'product' })
], Product);
exports.Product = Product;
exports.ProduceStatus = {
    Normal: 'normal',
    Disable: 'disable',
    Delete: 'delete'
};
class ProductType {
    constructor(name, value) {
        this.name = name;
        this.value = value;
    }
    static Prase(value) {
        switch (value) {
            case 'normal': return ProductType.Normal;
            case 'combo': return ProductType.Combo;
            default: throw new Error('不被允许的类型！');
        }
    }
    get Value() {
        return this.value;
    }
    get Name() {
        return this.name;
    }
}
ProductType.Normal = new ProductType('普通商品', 'normal');
ProductType.Combo = new ProductType('套餐', 'combo');
exports.ProductType = ProductType;
